import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

var _dec, _class;

/*
 * List - 租户级子账户列表
 * @date: 2018/11/19 20:31:56

 */
import React from 'react';
import { Form, Table, Badge } from 'antd';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { dateRender, operatorRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
/**
 * 租户级子账户列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} showEditModal 显示编辑模态框
 * @reactProps {Object} form 表单
 * @return React.element
 */

var ListTable = (_dec = Form.create({
  fieldNameProp: null
}), _dec(_class = /*#__PURE__*/function (_React$Component) {
  _inherits(ListTable, _React$Component);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          path = _this$props.path,
          currentUserId = _this$props.currentUserId,
          loading = _this$props.loading,
          searchPaging = _this$props.searchPaging,
          handleRecordEditBtnClick = _this$props.handleRecordEditBtnClick,
          showGroupModal = _this$props.showGroupModal,
          handleRecordAuthManageBtnClick = _this$props.handleRecordAuthManageBtnClick,
          onApiFieldPermission = _this$props.onApiFieldPermission,
          handleRecordUpdatePassword = _this$props.handleRecordUpdatePassword,
          _this$props$dataSourc = _this$props.dataSource,
          dataSource = _this$props$dataSourc === void 0 ? [] : _this$props$dataSourc,
          _this$props$paginatio = _this$props.pagination,
          pagination = _this$props$paginatio === void 0 ? {} : _this$props$paginatio,
          _this$props$openSecur = _this$props.openSecurityGroupDrawer,
          openSecurityGroupDrawer = _this$props$openSecur === void 0 ? function (e) {
        return e;
      } : _this$props$openSecur,
          handleUnlock = _this$props.handleUnlock,
          customizeTable = _this$props.customizeTable,
          handleViewEmployee = _this$props.handleViewEmployee;
      var columns = [{
        title: intl.get('ciam.subAccount.model.user.loginName').d('账号'),
        dataIndex: 'loginName',
        width: 120
      }, {
        title: intl.get('ciam.subAccount.model.user.realName').d('名称'),
        dataIndex: 'realName' // width: 220,

      }, {
        title: intl.get('ciam.subAccount.model.user.email').d('邮箱'),
        dataIndex: 'email',
        width: 300
      }, {
        title: intl.get('ciam.subAccount.model.user.phone').d('手机号码'),
        dataIndex: 'phone',
        width: 200,
        render: function render(phone, record) {
          if (record.internationalTelMeaning && record.phone) {
            // todo 需要改成好看的样子
            return "".concat(record.internationalTelMeaning, " | ").concat(record.phone);
          }

          return phone;
        }
      }, {
        title: intl.get('cpaas.common.date.active.from').d('有效日期从'),
        dataIndex: 'startDateActive',
        width: 120,
        render: dateRender
      }, {
        title: intl.get('cpaas.common.date.active.to').d('有效日期至'),
        dataIndex: 'endDateActive',
        width: 120,
        render: dateRender
      }, {
        title: intl.get('ciam.subAccount.model.user.enabled').d('冻结'),
        dataIndex: 'enabled',
        width: 80,
        render: function render(item) {
          return /*#__PURE__*/React.createElement(Badge, {
            status: item === true ? 'success' : 'error',
            text: item === false ? intl.get('cpaas.common.status.yes').d('是') : intl.get('cpaas.common.status.no').d('否')
          });
        }
      }, {
        title: intl.get('ciam.subAccount.model.user.locked').d('锁定'),
        dataIndex: 'locked',
        width: 80,
        render: function render(item) {
          return /*#__PURE__*/React.createElement(Badge, {
            status: item === false ? 'success' : 'error',
            text: item === true ? intl.get('cpaas.common.status.yes').d('是') : intl.get('cpaas.common.status.no').d('否')
          });
        }
      }, {
        title: intl.get('ciam.subAccount.model.user.userType').d('用户类型'),
        dataIndex: 'userTypeMeaning',
        width: 90
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        key: 'edit',
        width: 220,
        fixed: 'right',
        render: function render(_, record) {
          var _record$admin = record.admin,
              admin = _record$admin === void 0 ? false : _record$admin;
          var operators = [{
            key: 'edit',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.editList"),
                type: 'button',
                meaning: '子账户管理-编辑列表'
              }],
              onClick: function onClick() {
                handleRecordEditBtnClick(record);
              }
            }, intl.get('cpaas.common.button.edit').d('编辑')),
            len: 2,
            title: intl.get('cpaas.common.button.edit').d('编辑')
          }, {
            key: 'password',
            ele: admin || record.id === currentUserId ? null : /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.passwordUpdate"),
                type: 'button',
                meaning: '子账户管理-修改密码'
              }],
              onClick: function onClick() {
                handleRecordUpdatePassword(record);
              }
            }, intl.get('ciam.subAccount.view.option.passwordUpdate').d('修改密码')),
            len: 4,
            title: intl.get('ciam.subAccount.view.option.passwordUpdate').d('修改密码')
          }, {
            key: 'unlock',
            ele: record.locked && /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.unlock"),
                type: 'button',
                meaning: '子账户管理-解除锁定'
              }],
              key: "unlock",
              onClick: function onClick() {
                handleUnlock(record);
              }
            }, intl.get('ciam.subAccount.view.option.unlock').d('解除锁定')),
            len: 4,
            title: intl.get('ciam.subAccount.view.option.unlock').d('解除锁定')
          }];
          return operatorRender(operators);
        }
      }];
      var tableProps = {
        loading: loading,
        dataSource: dataSource,
        pagination: pagination,
        columns: columns,
        bordered: true,
        rowKey: 'id',
        scroll: {
          x: tableScrollWidth(columns)
        },
        onChange: searchPaging
      };
      return customizeTable({
        code: 'CIAM.SUB_ACCOUND.GRID'
      }, /*#__PURE__*/React.createElement(Table, tableProps));
    }
  }]);

  return ListTable;
}(React.Component)) || _class);
export { ListTable as default };